#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "stack.h"

void stack_create(stack *pstack)
{
	pstack->increment=50;
	pstack->start_size=50;
	pstack->current=0;
	pstack->size=pstack->start_size;
	pstack->data=(pointer*)malloc(pstack->start_size*sizeof(pointer));
}

void stack_push(stack *pstack, pointer value)
{
	if((pstack->current)==(pstack->size))
	{
		realloc(pstack->data, ((pstack->size)+(pstack->increment))*sizeof(pointer));
		pstack->size+=pstack->increment;
	}
	pstack->current++;
	pstack->data[pstack->current-1]=value;
}
void stack_destroy(stack *pstack)
{
	free(pstack->data);
	pstack->size=0;
	pstack->current=0;
}

size_t stack_size(stack *pstack)
{
	return pstack->size;
}

pointer stack_pop(stack *pstack)
{
	if((pstack->current)==0)
	{
		return 0;
	}
	pstack->current--;
	return pstack->data[pstack->current];
}

pointer stack_peek(stack *pstack)
{
	if((pstack->current)==0)
	{
		return 0;
	}
	return pstack->data[pstack->current-1];
}
void stack_tune(stack *pstack, size_t initial_size, size_t increment)
{
	pstack->start_size = initial_size;
	pstack->increment = increment;
}
